import { Component, OnInit } from '@angular/core';
import { User } from "../domain/user";
import { UserService } from "../service/user.service";
import { Router } from "@angular/router";
import { postUser } from "../domain/user";

@Component({
  selector: 'app-log-in-interface',
  templateUrl: './log-in-interface.component.html',
  styleUrls: ['./log-in-interface.component.css']
})
export class LogInInterfaceComponent implements OnInit {

  // userModel = new User("","");

  constructor(private userService: UserService, private  _router: Router) {

  }

  staffLogIn(username: string, password: string) {
    username = username.trim();
    password = password.trim();
    var userModel: postUser = new postUser(username, password);

    this.userService.staffLogInService(userModel)
      .then( (getUser) => {
        // this.userService.sharedUser = new User();
        this.userService.sharedUser = getUser;
        console.log(getUser);
        // if(this.userService.sharedUser.department === "行政部") {
        //   this._router.navigateByUrl('/administration-staff-attendance/default-interface');
        // } else if(this.userService.sharedUser.position === "普通员工") {
        //   this._router.navigateByUrl('/staff-attendance/default-interface')
        // } else {
        //   this._router.navigateByUrl('/manager-system/default-interface')
        // }
        if(this.userService.sharedUser.position === "部门经理" || this.userService.sharedUser.position === "总经理" || this.userService.sharedUser.position === "副总经理") {
          this._router.navigateByUrl('/manager-system/default-interface')
        } else if (this.userService.sharedUser.department === "行政部") {
          this._router.navigateByUrl('/administration-staff-attendance/default-interface');
        } else {
          this._router.navigateByUrl('/staff-attendance/default-interface')
        }
      })

  }

  ngOnInit() {
  }

}
